package com.gaojinqi.order.message;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * 通过output发送消息
 */
@Component
public class SendingBean {

    @Autowired
    private StreamClient streamClient;

    @Autowired
    private MessageChannel output;

    /**
     * 通过注入绑定接口（@output绑定的channel）的output方法发送消息
     *
     * @param name
     */
    public void sendWithOutput(String name) {
        streamClient.output().send(MessageBuilder.withPayload(name).build());
    }

    /**
     * 通过绑定通道也可以直接注入，变量名output是绑定的channel
     *
     * @param name
     */
    public void sendWith(String name) {
        output.send(MessageBuilder.withPayload(name).build());
    }
}
